package cn.hchaojie.camp.day02.exercise;

/**
 * 写一个方法，传入一个整型数组，判断数组里面所有的元素是否已排序。
 * 
 * @author hchaojie
 *
 */
public class ArrayIsSorted {
	public static void main(String[] args) {
		int[] numbers1 = {1, 2, 3, 4};
		int[] numbers2 = {};
		int[] numbers3 = {4, 2, 3, 1};
		int[] numbers4 = {5, 10, 21, 30, 5};
		System.out.println(isSorted(numbers1));
		System.out.println(isSorted(numbers2));
		System.out.println(isSorted(numbers3));
		System.out.println(isSorted(numbers4));
	}

	public static boolean isSorted(int[] numbers) {
		for (int i = 0; i < numbers.length - 1; i++) {
			if (numbers[i] > numbers[i + 1]) {
				return false;
			}
		}
		
		return true;
	}
}
